/***房屋列表JS**/

/**
Author ffpan
Date 2010-04-24
Version 1.0
**/


$(document).ready(function(){
	initTips($("#s_plaza"));

	/*$("#searchdiv").bind("click" , function(e){
		var el = e.target;
		var cat , mouse;
		if(el.tagName=="A"){
			cat = el.parentNode.parentNode.getAttribute("cat");
			mouse = el.getAttribute("mouse");
			setHidden(cat , mouse);
		}
	});*/
	if($("#searchdiv")){
		var sels = $("#searchdiv select");
		for(var i=0 , l= sels.length ; i<l; i++){
			$(sels[i]).val($(sels[i]).attr("ovalue"));
			$(sels[i]).bind("change" , function(){submitForm(true);});
		}
	}
	
	if($("#clearAll")){
		$("#clearAll").bind("click" , function(){
			var sels = $("#searchdiv select");
			for(var i=0 , l= sels.length ; i<l; i++){
				$(sels[i]).val("");
			}
			submitForm(true);
		});
	}
	
	$("#splazabtn").bind("click" , function(e){
		submitForm(true);
	});

	$("#ordersel").bind("change" , function(){
		$("#s_type").val($(this).val());
		submitForm(false);
	});

	document.getElementById("ordersel").selectedIndex = parseInt($("#s_type").val())-1;
	
	$("#hiddenarea input[type=hidden]").each(function(i , item){
		setShowCls($(item).attr("refel") , $(item).val());
	});

	if($("#s_page").val()==1){$("#prepage").css("visibility" , "hidden");}else{$("#prepage").css("visibility" , "visible");}
	if($("#s_page").val()==$("#pagetotal").val()){$("#nextpage").css("visibility" , "hidden");}else{$("#nextpage").css("visibility" , "visible");}

	$("#prepage").bind("click" , function(){
		if($("#s_page").val()=="1"){return;}
		var key =$("#key").val(); 
		var page = parseInt($("#s_page").val());
		 $("#s_page").val(page-1);
		 $("#pn").html(page-1);
		 submitForm(false);
	});

	
	$("#nextpage").bind("click" , function(){
		if($("#s_page").val()==$("#pagetotal").val()){return;}
		var key =$("#key").val(); 
		var page = parseInt($("#s_page").val());
		$("#s_page").val(page+1);
		$("#pn").html(page+1);
		submitForm(false);
	});
	
	var lastoverel = null;
	$("#salelist").bind("mouseover" , hoverTable);
	$("#salelist").bind("click" , clickTable);
	
	function hoverTable(e){
		var el = e.target;
		while(el.tagName!="TR"){
			el = el.parentNode;
		}
		el = $(el);
		if(lastoverel!=null){lastoverel.removeClass("sel");}
		el.addClass("sel");
		lastoverel = el;
	}
	
	function clickTable(e){
		var el = e.target;
		while(el.tagName!="TR"){
			el = el.parentNode;
		}
		//el = $(el);
		link = el.getElementsByTagName("a")[0].getAttribute("hreftag");
		window.open(link);
	}
});

function submitForm(clearpage){
	if(clearpage){$("#s_page").val(1);}
	if($("#s_plaza").val()==$("#s_plaza").attr("tips")){$("#s_plaza").val("");}
	$("#listform").submit();
}

function setHidden(dom , value){
	var el = document.getElementById(dom);
	if(el){el.value = value;}
	submitForm(true);
}

function setShowCls(refel , val){
	$("#"+refel+" a").each(function(i , item){
		if($(item).attr("mouse")==val){
			$(item).addClass("sel");
		}
	});
	
}